package com.eshop.modules.system.service.mapper;

import java.util.Set;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import com.eshop.modules.system.domain.Menu;
import com.eshop.common.mapper.CoreMapper;

@Repository
@Mapper
public interface MenuMapper extends CoreMapper<Menu>
{
    @Select({ "SELECT * from menu m where m.pid = #{pid} and m.is_del = 0 " })
    List<Menu> findByPid(@Param("pid") final long pid);
    
    @Select({ "select m.* from menu m LEFT JOIN roles_menus t on m.id= t.menu_id LEFT JOIN role r on r.id = t.role_id where r.id = #{roleId} and m.is_del=0" })
    Set<Menu> findMenuByRoleId(@Param("roleId") final Long roleId);
    
    @Select({ "<script>select m.* from menu m LEFT OUTER JOIN roles_menus t on m.id= t.menu_id LEFT OUTER JOIN role r on r.id = t.role_id where m.is_del=0 and m.type!=2 and  r.id in <foreach collection=\"roleIds\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item}</foreach> order by m.sort asc</script>" })
    List<Menu> selectListByRoles(@Param("roleIds") final List<Long> roleIds);
}
